<style>
    .am-tabs-bd {
        z-index: 1;
    }
</style>
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <form id="my-form" class="am-form tpl-form-line-form" enctype="multipart/form-data" method="post">
                    <div class="widget-body">
                        <fieldset>
                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">基础设置</div>
                            </div>
                            <div class="am-tabs am-margin-top" data-am-tabs="{noSwipe: 1}">
                                <ul class="am-tabs-nav am-nav am-nav-tabs">
                                    <li class="am-active"><a href="#tab1">站点设置</a></li>
                                    <li class=""><a href="#tab2">报修设置</a></li>
                                </ul>
                                <div class="am-tabs-bd">
                                    <!-- 基础 -->
                                    <div class="am-tab-panel am-active am-margin-top-lg" id="tab1">
                                        <div class="am-form-group">
                                            <label class="am-u-sm-3 am-form-label form-require"> 站点名称 </label>
                                            <div class="am-u-sm-9">
                                                <input type="text" class="tpl-form-input" name="site[site_name]"
                                                        value="<?= $info['site']['site_name'] ?>" required>
                                            </div>
                                        </div>
                                        <div class="am-form-group">
                                            <label class="am-u-sm-3 am-form-label form-require"> 联系方式 </label>
                                            <div class="am-u-sm-9">
                                                <input type="text" class="tpl-form-input" name="site[site_tel]"
                                                        value="<?= $info['site']['site_tel'] ?>">
                                            </div>
                                        </div>

                                        <div class="am-form-group">
                                            <label class="am-u-sm-3 am-form-label form-require"> 网站开关 </label>
                                            <div class="am-u-sm-9">
                                                <{html_radios1("site[site_status]",$yesRadio,$info.site.site_status)}>
                                            </div>
                                        </div>
                                    </div>
                                    <!-- 其他 -->
                                    <div class="am-tab-panel am-margin-top-lg" id="tab2">

                                        <div class="am-form-group">
                                            <label class="am-u-sm-3 am-form-label form-require"> 报修模式 </label>
                                            <div class="am-u-sm-9">
                                                <{html_radios1("baoxiu[bx_moshi]",$moshiRadio,$info.baoxiu.bx_moshi)}>
                                            </div>
                                        </div>
                                        <div class="am-form-group">
                                            <label class="am-u-sm-3 am-form-label form-require"> 短信开关 </label>
                                            <div class="am-u-sm-9">
                                                <{html_radios1("baoxiu[sms_status]",$yesRadio,$info.baoxiu.sms_status)}>
                                            </div>
                                        </div>
                                        <div class="am-form-group">
                                            <label class="am-u-sm-3 am-form-label form-require"> 接收人员 </label>
                                            <div class="am-u-sm-9">
                                                <{html_checkboxes1("baoxiu[sms_user]",$userLevels,$info.baoxiu.sms_user)}>
                                                <div class="help-block">
                                                    <small>注：</small>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="am-form-group">
                                            <label class="am-u-sm-3 am-form-label form-require"> 短信发送 </label>
                                            <div class="am-u-sm-9">
                                                <{html_checkboxes1("baoxiu[sms_order]",$orderStatus,$info.baoxiu.sms_order)}>
                                                <div class="help-block">
                                                    <small>注：</small>
                                                </div>
                                            </div>
                                        </div>

                                    </div>
                                    
                                </div>
                            </div>
                            <div class="am-form-group">
                                <div class="am-u-sm-9 am-u-sm-push-3 am-margin-top-lg">
                                    <button type="submit" class="j-submit am-btn am-btn-secondary">提交
                                    </button>
                                </div>
                            </div>                                        
                        </fieldset>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<!-- 图片文件列表模板 -->
<{include file="admin/public/_template/tpl_file_item.php"}>
<!-- 文件库弹窗 -->
<{include file="admin/public/_template/file_library.php"}>
<script src="/static/assets/common/js/vue.min.js"></script>
<script src="/static/assets/common/js/ddsort.js"></script>
<script src="/static/assets/common/plugins/umeditor/umeditor.config.js?v=<?= $version ?>"></script>
<script src="/static/assets/common/plugins/umeditor/umeditor.min.js"></script>
<script src="/static/assets/store/js/select.data.js?v=<?= $version ?>"></script>
<script>
    $(function () {

        // 富文本编辑器
        UM.getEditor('container', {
            initialFrameWidth: 575 + 15,
            initialFrameHeight: 200
        });

        // 选择图片
        $('.upload-file').selectImages({
            name: 'site[site_logo]'
            , multiple: false
        });

        // 图片列表拖动
        $('.uploader-list').DDSort({
            target: '.file-item',
            delay: 100, // 延时处理，默认为 50 ms，防止手抖点击 A 链接无效
            floatStyle: {
                'border': '1px solid #ccc',
                'background-color': '#fff'
            }
        });

        /**
         * 表单验证提交
         * @type {*}
         */
        $('#my-form').superForm();

        // 切换默认上传方式
        $("input:radio[name='storage[default]']").change(function (e) {
            $('.form-tab-group').removeClass('active');
            $('#' + e.currentTarget.value).addClass('active');
        });
        $("input:radio[name='sms[status]']").change(function (e) {
            $('.form-tab-group').removeClass('active');
            if(e.currentTarget.value == '1'){
                $('#sms').addClass('active');
            }
            
        });

        /**
         * 发送测试短信
         */
        $('.j-sendTestMsg').click(function () {
            var msgType = $(this).data('msg-type')
                , formData = {
                AccessKeyId: $('input[name="sms[engine][aliyun][AccessKeyId]"]').val()
                , AccessKeySecret: $('input[name="sms[engine][aliyun][AccessKeySecret]"]').val()
                , sign: $('input[name="sms[engine][aliyun][sign]"]').val()
                , msg_type: msgType
                , template_code: $('input[name="sms[engine][aliyun][' + msgType + '][template_code]"]').val()
                , accept_phone: $('input[name="sms[engine][aliyun][' + msgType + '][accept_phone]"]').val()
            };
            if (!formData.AccessKeyId.length) {
                layer.msg('请填写 AccessKeyId');
                return false;
            }
            if (!formData.AccessKeySecret.length) {
                layer.msg('请填写 AccessKeySecret');
                return false;
            }
            if (!formData.sign.length) {
                layer.msg('请填写 短信签名');
                return false;
            }
            if (!formData.template_code.length) {
                layer.msg('请填写 模板ID');
                return false;
            }
            if (!formData.accept_phone.length) {
                layer.msg('请填写 接收手机号');
                return false;
            }
            layer.confirm('确定要发送测试短信吗', function (index) {
                var load = layer.load();
                var url = "<?= url('setting/smsTest') ?>";
                $.post(url, formData, function (result) {
                    layer.msg(result.msg);
                    layer.close(load);
                });
                layer.close(index);
            });
        });


    });
</script>
